//
//  KCUserListVC.m
//  Golden
//
//  Created by king on 2017/8/16.
//  Copyright © 2017年 KC. All rights reserved.
//

#import "KCKit.h"
#import "KCUserListVC.h"
#import "KCHomeUserCell.h"
#import "KCHomeModel.h"

@interface KCUserListVC ()<UITableViewDataSource,UITableViewDelegate,KCStationDelegate>

@property(nonatomic,strong)KCStation *station;
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray <ploys *>*dataArray;

@end

@implementation KCUserListVC

#pragma mark - LifeCycle

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createNews];
    [self requestNews];
}

- (void)dealloc {
    [KCStation RevokeStation:_station];
    KCLog(@"♻️ Dealloc %@", NSStringFromClass([self class]));
}

#pragma mark - Setup

- (void)createNews{
    
    self.KCTitleLable.text = @"取金专栏";
    
    _station = [KCStation RegisterStation:KHttpStationHomeUsers delegate:self];
    
    _dataArray = [NSMutableArray array];
    
    _tableView = [[UITableView alloc]initWithFrame:TABLE_FRAME style:TABLE_STYLE_G];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    
}

- (void)requestNews {
    
    
    
}

#pragma mark - 网络请求回掉

- (id)dispatch:(KCCargo *)cargo{
    
    if (cargo.cargoID == 0x01) {
        
        NSDictionary *dic = (NSDictionary *)cargo.cargoObj;
        
        NSDictionary *dataDic = dic[@"attachment"];
        
        NSArray *daArray = dataDic[@"ploys"];
        
        [daArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
           
            ploys *model = [ploys modelWithDictionary:obj];
            [_dataArray addObject:model];
        }];
        
        [_tableView reloadData];
        
        KCLog(@"%@",dic);
        
        
    }
    
    return nil;
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataArray.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    KCHomeUserCell *cell = [KCHomeUserCell cellWithTableView:tableView];
    cell.model = _dataArray[indexPath.row];
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}



@end
